using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MonsterController : MonoBehaviour
{
    /// <summary>
    /// 最大生命值
    /// </summary>
    public float MaxHP { get; set; } = 100.0f;
    /// <summary>
    /// 当前生命值
    /// </summary>
    public float CurrentHP { get; set; }

    /// <summary>
    /// 等级
    /// </summary>
    public int Level { get; set; } = 1;

    /// <summary>
    /// 等级和属性
    /// </summary>
    public Dictionary<int, LunaProperties> LevelProperties { get; private set; } = new()
    {
        {
            1, new()
            {
                AD = 10,
                AP = 10
            }
        },
        {
            2, new()
            {
                AD = 20,
                AP = 20
            }
        }
    };

    void Awake()
    {
        this.CurrentHP = MaxHP;
    }

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void ChangeHP(float amount)
    {
        this.CurrentHP = Mathf.Clamp(this.CurrentHP + amount, 0, this.MaxHP);

        if (this.IsDead())
        {
            var currentQuest = QuestSystem.Instance.CurrentQuest as KillMonsters;
            currentQuest.KilledCount++;
            if (currentQuest.KilledCount >= 3)
            {
                // 怪物杀完了
                currentQuest.Status = QuestStatus.Completed;
                GameManager.Instance.PlaySoundCompleteQuest();
            }
        }
    }
    
    public bool IsDead() => this.CurrentHP <= 0;
    
    public float GetAD()
    {
        var properties = this.LevelProperties[this.Level];
        return properties.AD + properties.BonusAD;
    }
}
